<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once('../../_inc/funct.tabDati.php');
require_once './_inc/funct.rigeneraCodice.php';

if (reqVar('azione') == 'gencod') {
	$msgPag .= rigeneraCodiceAll();
} 

$aWhere = array();
if (reqVar('pagifilt')!='') {
	$aWhere[] = " (t.descr LIKE '%".addslashes(reqVar('pagifilt'))."%' "
		." OR t.cod_set_dati LIKE '%".addslashes(reqVar('pagifilt'))."%') ";
}
$sWhere = (count($aWhere)==0)? "":" WHERE ".implode(" AND ",$aWhere);
$sql_sel = "SELECT count(*) AS num_rec " .
		" FROM rgl_set_dati t " .$sWhere;
//dbg_($sql_sel);
$objDB->query($sql_sel,'selRec');
$acRec = $objDB->fetch('selRec');
$numRec = $acRec['num_rec'];
$link = $_SERVER['PHP_SELF']."?".$sXSNQS;
$startOffset = 0;
$endOffset = 0;
$sFiltro = rglGetFiltro($link);
$sPaginaz = rglGetPaginaz($link, $numRec, $startOffset, $endOffset);

$sql_sel = "SELECT t.*" .
		" FROM rgl_set_dati t ".$sWhere .
		" ORDER BY t.cod_set_dati ".
		" LIMIT ".$startOffset.",".($endOffset-$startOffset);
$objDB->query($sql_sel,'selRec');
$cmdL = "";
$cmdL .= "<a class=\"cmd1\" href=\"setDatiList.php?azione=gencod&$sXSNQS\">rigenera codice</a>";

$cmdR = "&nbsp;&nbsp;&nbsp;";
if (true) {
	$cmdR .= "<a class=\"cmd1\" href=\"setDatiIns.php?$sXSNQS\">nuovo set</a>";
}
$cmdR .= cmdTorna(); 
testaHtml('Gestione modelli', $msgPag, 'modl');
echo getHtmlForm();
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('sd');
echo getHtmlHidden('startoffset');
?>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
   <tr>
      <td class="cmd1" align="left">
			<?=$sFiltro?>
      </td>
      <td class="cmd1" align="right">
			<?=$sPaginaz?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="tit1" colspan='6' align='center'>Lista set dati di bilancio</td>
   </tr>
   <tr>
      <td class="lab1" width='10%' align='center'>Codice</td>
      <td class="lab1" width='50%' align='center'>Descrizione</td>
      <td class="lab1" width='10%' align='center'>Fonte bil.</td>
     	<td class="lab1" width='10%' align='center'>Indici 1</td>
      <td class="lab1" width='10%' align='center'>Indici 2</td>
      <td class="lab1" width='10%' align='center'>Indici 3</td>
   </tr>
			<? 
$clRF = 'txt2';
while($acX = $objDB->fetch('selRec')) { 
	$clRF = ($clRF=='txt1')?'txt2':'txt1';	
?>
   <tr>
      <td class="<?=$clRF?>">
      	<a href='setDatiVis.php?sd=<?=$acX['id_set_dati']."&$sXSNQS"?>' class="<?=$clRF?>"
      	 	style='font-family:lucida console,courier;'>
            <?
            echo $acX['cod_set_dati'];
            ?>
         </a>
      </td>
      <td class="<?=$clRF?>" align='left'><? echo $acX['descr']; ?></td>
      <td class="<?=$clRF?>" align='left'><? echo $acX['fonte_bil']; ?></td>
      <td class="<?=$clRF?>" align='left'><? echo $acX['indici1']; ?></td>
      <td class="<?=$clRF?>" align='left'><? echo $acX['indici2']; ?></td>
      <td class="<?=$clRF?>" align='left'><? echo $acX['indici3']; ?></td>
   </tr><? 
}?>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         &nbsp;
      </td>
      <td class="cmd1" align="right">
<?=$sPaginaz?>
      </td>
   </tr>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();


function rigeneraCodiceAll() {
	global $objDB;
	global $sDBG;
	$msg = '';
	$sSql = "SELECT * FROM rgl_set_dati ORDER BY cod_set_dati ";
	//dbg_($sSql);
	$objDB->exec($sSql,'selAllSD');
	while ($acX=$objDB->fetch('selAllSD')) {
		$msg .= $acX['cod_set_dati'].' - '.rigeneraCodice($acX['id_set_dati']).'<br/>';
	}
	return $msg;
}
